import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import eslintPlugin from 'vite-plugin-eslint';
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
import ElementPlus from 'unplugin-element-plus/vite';
import * as path from 'path';
export default defineConfig({
	resolve: {
		alias: {
			'@': path.resolve(__dirname, 'src'),
		},
	},
	plugins: [
		vue(),
		eslintPlugin({
			fix: true, //修复错误
			include: ['src/**/*.ts', 'src/**/*.vue', 'src/*.ts', 'src/*.vue'],
		}),
		AutoImport({
			imports: ['vue', 'pinia', 'vue-router', 'vue-i18n'],
			resolvers: [ElementPlusResolver()],
			eslintrc: {
				enabled: false, // 1、改为true用于生成eslint配置。2、生成后改回false，避免重复生成消耗
				filepath: './.eslintrc-auto-import.json', // 指定自动导入函数 eslint 规则的文件
			},
			dts: 'src/types/auto-import.d.ts',
		}),
		Components({
			resolvers: [ElementPlusResolver()],
			dts: 'src/types/components.d.ts',
		}),
		ElementPlus({}),
	],
	css: {
		preprocessorOptions: {
			scss: {
				additionalData: '@import "@/styles/index.scss";',
			},
		},
	},
	server: {
		host: '0.0.0.0', // ip
		port: 8081,
		hmr: true, // 热启动
		open: true, // 自动打开浏览器
	},
});
